{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ff3a0873",
   "metadata": {},
   "outputs": [],
   "source": [
    "from torch import nn\n",
    "import torch\n",
    "class ConcatFusion(nn.Module):\n",
    "    def __init__(self, input_dim=1024, hidden_dim=1024):\n",
    "        super().__init__()\n",
    "        self.fc = nn.Sequential(\n",
    "            nn.Linear(input_dim * 2, hidden_dim),\n",
    "            nn.ReLU(),\n",
    "            nn.Linear(hidden_dim, input_dim)  # 可选输出维度\n",
    "        )\n",
    "\n",
    "    def forward(self, feat1, feat2):\n",
    "        # feat shape: [1024, 1] -> [1, 1024]\n",
    "        feat1 = feat1.view(1, -1)\n",
    "        feat2 = feat2.view(1, -1)\n",
    "\n",
    "        x = torch.cat([feat1, feat2], dim=1)\n",
    "        out = self.fc(x)\n",
    "\n",
    "        return out.view(-1, 1)  # 回复成 [1024, 1]\n",
    "\n",
    "a = torch.randn((1024,1))\n",
    "b = torch.randn((1024,1))\n",
    "cf = ConcatFusion()\n",
    "res = cf(a,b)\n",
    "print(res.shape)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bbd3df54",
   "metadata": {},
   "outputs": [],
   "source": [
    "#=============T2I Adapter============\n",
    "from diffusers import StableDiffusionXLAdapterPipeline, T2IAdapter, EulerAncestralDiscreteScheduler, AutoencoderKL\n",
    "import torch\n",
    "\n",
    "# load adapter\n",
    "adapter = T2IAdapter.from_config(T2IAdapter.load_config('../t2i-adapter-openpose-sdxl-1.0'))\n",
    "\n",
    "adapter_state = adapter(torch.randn(1,3,256,256))\n",
    "print(len(adapter_state))\n",
    "for k, v in enumerate(adapter_state):\n",
    "    print(k)\n",
    "    adapter_state[k] = v * 0.5\n",
    "print(adapter_state)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "7deb4d06",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "dict_keys(['optimizer_state', 'scheduler_state', 'unet', 'pose_net'])\n"
     ]
    }
   ],
   "source": [
    "import torch\n",
    "\n",
    "ans = torch.load(\"outputs/pgmodel.pth\")\n",
    "print(ans.keys())"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "flowers",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
